From 8dae11e100677217c6b4cd858a76f3bf6bc8d12c Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 18 Jul 2022 05:52:07 -0600 Subject: [PATCH] use QStringView with namepart parameter in add wpt functions. (#891) * use QStringView with namepart parameter in add wpt functions. * update includes --- defs.h | 61 +++++++++++++++++++++++++---------------------- qstarz_bl_1000.cc | 2 +- route.cc | 20 ++++++++-------- waypt.cc | 19 +++++++++------ 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/defs.h b/defs.h index 961384837..eed1a18f3 100644 --- a/defs.h +++ b/defs.h @@ -19,36 +19,39 @@ #ifndef DEFS_H_INCLUDED_ #define DEFS_H_INCLUDED_ -#include // for sort, stable_sort -#include // for M_PI -#include // for va_list -#include // for NULL, nullptr_t, size_t -#include // for int32_t, uint32_t -#include // for NULL, fprintf, FILE, stdout -#include // for time_t -#include // for optional -#include // for move +#include // for sort, stable_sort +#include // for M_PI +#include // for va_list +#include // for NULL, nullptr_t, size_t +#include // for int32_t, uint32_t +#include // for NULL, fprintf, FILE, stdout +#include // for time_t +#include // for optional +#include // for move #if HAVE_LIBZ -#include // doesn't really belong here, but is missing elsewhere. +#include // doesn't really belong here, but is missing elsewhere. #elif !ZLIB_INHIBITED -#include "zlib.h" // doesn't really belong here, but is missing elsewhere. +#include "zlib.h" // doesn't really belong here, but is missing elsewhere. #endif -#include // for QDebug -#include // for QList, QList<>::const_reverse_iterator, QList<>::reverse_iterator -#include // for QScopedPointer -#include // for QString -#include // for QTextCodec -#include // for QVector -#include // for CaseInsensitive -#include // for foreach - -#include "formspec.h" // for FormatSpecificData -#include "inifile.h" // for inifile_t -#include "gbfile.h" // doesn't really belong here, but is missing elsewhere. -#include "session.h" // for session_t -#include "src/core/datetime.h" // for DateTime +#include // for QDateTime +#include // for QDebug +#include // for QList, QList<>::const_iterator, QList<>::const_reverse_iterator, QList<>::count, QList<>::reverse_iterator +#include // for QScopedPointer +#include // for QScopedPointerPodDeleter +#include // for QString +#include // for QStringView +#include // for QTextCodec +#include // for QVector +#include // for CaseInsensitive +#include // for QForeachContainer, qMakeForeachContainer, foreach, qint64 + +#include "formspec.h" // for FormatSpecificData +#include "inifile.h" // for inifile_t +#include "gbfile.h" // doesn't really belong here, but is missing elsewhere. +#include "session.h" // for session_t +#include "src/core/datetime.h" // for DateTime #define CSTR(qstr) ((qstr).toUtf8().constData()) @@ -533,7 +536,7 @@ class WaypointList : private QList { public: void waypt_add(Waypoint* wpt); // a.k.a. append(), push_back() - void add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, const QString& namepart, int number_digits); + void add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, QStringView namepart, int number_digits); // FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead, // and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst(). void waypt_del(Waypoint* wpt); // a.k.a. erase() @@ -709,7 +712,7 @@ public: void del_head(route_head* rte); // a.k.a. erase() // FIXME: Generally it is inefficient to use an element pointer or reference to define the insertion point, use iterator instead. void insert_head(route_head* rte, route_head* predecessor); // a.k.a. insert - void add_wpt(route_head* rte, Waypoint* wpt, bool synth, const QString& namepart, int number_digits); + void add_wpt(route_head* rte, Waypoint* wpt, bool synth, QStringView namepart, int number_digits); // FIXME: Generally it is inefficient to use an element pointer or reference to define the insertion point, use iterator instead. void del_wpt(route_head* rte, Waypoint* wpt); void common_disp_session(const session_t* se, route_hdr rh, route_trl rt, waypt_cb wc); @@ -767,8 +770,8 @@ void route_del_head(route_head* rte); void track_add_head(route_head* rte); void track_del_head(route_head* rte); void track_insert_head(route_head* rte, route_head* predecessor); -void route_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart = "RPT", int number_digits = 3); -void track_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart = "RPT", int number_digits = 3); +void route_add_wpt(route_head* rte, Waypoint* wpt, QStringView namepart = u"RPT", int number_digits = 3); +void track_add_wpt(route_head* rte, Waypoint* wpt, QStringView namepart = u"RPT", int number_digits = 3); void route_del_wpt(route_head* rte, Waypoint* wpt); void track_del_wpt(route_head* rte, Waypoint* wpt); //void route_disp(const route_head* rte, waypt_cb); /* template */ diff --git a/qstarz_bl_1000.cc b/qstarz_bl_1000.cc index 739af5aeb..1707da3d9 100644 --- a/qstarz_bl_1000.cc +++ b/qstarz_bl_1000.cc @@ -259,7 +259,7 @@ QstarzBL1000Format::qstarz_bl_1000_read_record(QDataStream& stream, route_head* } waypt_add(waypoint); } else if (qstarz_bl_1000_is_trackpoint_type(type)) { - track_add_wpt(track_route, waypoint, "TP", 3); + track_add_wpt(track_route, waypoint, u"TP", 3); } else { delete waypoint; } diff --git a/route.cc b/route.cc index dea0dba26..d06cfc732 100644 --- a/route.cc +++ b/route.cc @@ -19,16 +19,17 @@ #include // for assert #include // for nullptr_t -#include // for sort -#include #include // for optional, operator>, operator< -#include // for QDateTime -#include // for QList<>::iterator +#include // for operator>, QDateTime, operator< +#include // for QList<>::const_iterator #include // for QString -#include // for foreach +#include // for qMakeStringPrivate, QStringLiteral +#include // for QStringView +#include // for QForeachContainer, qMakeForeachContainer, foreach #include "defs.h" +#include "formspec.h" // for FormatSpecificDataList #include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers #include "session.h" // for curr_session, session_t (ptr only) #include "src/core/datetime.h" // for DateTime @@ -103,7 +104,7 @@ track_insert_head(route_head* rte, route_head* predecessor) } void -route_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int number_digits) +route_add_wpt(route_head* rte, Waypoint* wpt, QStringView namepart, int number_digits) { // First point in a route is always a new segment. // This improves compatibility when reading from @@ -116,7 +117,7 @@ route_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int numbe } void -track_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int number_digits) +track_add_wpt(route_head* rte, Waypoint* wpt, QStringView namepart, int number_digits) { // First point in a track is always a new segment. // This improves compatibility when reading from @@ -408,7 +409,7 @@ RouteList::insert_head(route_head* rte, route_head* predecessor) // in the RouteList AND any routes that have had waypoints added but haven't been // added themselves yet. void -RouteList::add_wpt(route_head* rte, Waypoint* wpt, bool synth, const QString& namepart, int number_digits) +RouteList::add_wpt(route_head* rte, Waypoint* wpt, bool synth, QStringView namepart, int number_digits) { ++waypt_ct; rte->waypoint_list.add_rte_waypt(waypt_ct, wpt, synth, namepart, number_digits); @@ -456,7 +457,6 @@ RouteList::copy(RouteList** dst) const *dst = new RouteList; } - const char RPT[] = "RPT"; for (const auto& rte_old : *this) { auto* rte_new = new route_head; // waypoint_list created below with add_wpt. @@ -471,7 +471,7 @@ RouteList::copy(RouteList** dst) const (*dst)->add_head(rte_new); const auto& old_list = rte_old->waypoint_list; for (const auto& old_wpt : old_list) { - (*dst)->add_wpt(rte_new, new Waypoint(*old_wpt), false, RPT, 3); + (*dst)->add_wpt(rte_new, new Waypoint(*old_wpt), false, u"RPT", 3); } } } diff --git a/waypt.cc b/waypt.cc index d87bc9b6c..68e2d6684 100644 --- a/waypt.cc +++ b/waypt.cc @@ -21,22 +21,27 @@ #include // for assert #include // for fabs -#include // for printf, fflush, fprintf, stdout -#include // for stable_sort +#include // for fflush, fprintf, stdout #include // for QChar #include // for QDateTime -#include // for QList +#include // for QDebug +#include // for QLatin1Char +#include // for QList<>::const_iterator #include // for QString, operator== +#include // for qMakeStringPrivate, QStringLiteral +#include // for QStringView #include // for QTime -#include // for qPrintable +#include // for QForeachContainer, qMakeForeachContainer, foreach, qint64 #include "defs.h" -#include "garmin_fs.h" // for garmin_ilink_t, garmin_fs_t, GMSD_FIND +#include "formspec.h" // for FormatSpecificDataList +#include "garmin_fs.h" // for garmin_ilink_t, garmin_fs_t #include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers #include "session.h" // for curr_session, session_t #include "src/core/datetime.h" // for DateTime -#include "src/core/logging.h" // for Warning, Fatal +#include "src/core/logging.h" // for FatalMsg + WaypointList* global_waypoint_list; @@ -638,7 +643,7 @@ WaypointList::waypt_add(Waypoint* wpt) } void -WaypointList::add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, const QString& namepart, int number_digits) +WaypointList::add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, QStringView namepart, int number_digits) { append(wpt); -- 2.30.2